﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using DoubleLinkedList;

namespace UnitTestDoubleLinkedList
{
    [TestClass]
    public class UnitTest1
    {
        private DLL<int> list = new DLL<int>();

        [TestMethod]
        public void IsEmpty()
        {
            Assert.AreEqual(true, list.Empty);
        }

        [TestMethod]
        public void AddFirst_CheckFirst()
        {
            Assert.AreEqual(true, list.Empty);
            list.AddFirst(10);
            Assert.AreEqual(10, list.First.Data);
            list.AddFirst(20);
            Assert.AreEqual(20, list.First.Data);
        }

        [TestMethod]
        public void Count()
        {
            Assert.AreEqual(0, list.Count);
            list.AddFirst(10);
            Assert.AreEqual(1, list.Count);
            list.AddFirst(10);
            Assert.AreEqual(2, list.Count);
        }

        [TestMethod]
        public void AddLast_CheckLast()
        {
            list.AddFirst(10);
            Assert.AreEqual(10, list.Last.Data);
            list.AddFirst(20);
            Assert.AreEqual(10, list.Last.Data);
            list.AddLast(30);
            Assert.AreEqual(30, list.Last.Data);
            Assert.AreEqual(20, list.First.Data);
        }

        [TestMethod]
        public void Clear()
        {
            Assert.AreEqual(true, list.Empty);
            list.AddFirst(10);
            list.AddFirst(10);
            list.AddFirst(10);
            Assert.AreEqual(false, list.Empty);
            list.Clear();
            Assert.AreEqual(true, list.Empty);
            Assert.AreEqual(0, list.Count);
        }

        [TestMethod]
        public void Contains()
        {
            Assert.AreEqual(false, list.Contains(10));
            list.AddFirst(10);
            Assert.AreEqual(true, list.Contains(10));
            list.AddFirst(20);
            list.AddFirst(30);
            list.AddLast(50);
            Assert.AreEqual(true, list.Contains(20));
            Assert.AreEqual(true, list.Contains(50));
            list.Clear();
            Assert.AreEqual(false, list.Contains(50));
        }

        [TestMethod]
        public void Find()
        {
            list.AddFirst(10);
            Assert.AreEqual(true, list.Contains(10));
            list.AddFirst(20);
            list.AddFirst(30);
            list.AddLast(50);
            Node<int> n = list.Find(50);
            Assert.AreEqual(50, n.Data);
        }

        [TestMethod]
        public void Remove()
        {
            list.AddFirst(20);
            list.AddFirst(30);
            list.AddLast(50);
            list.Remove(30);
            Assert.AreEqual(false, list.Contains(30));
        }

        [TestMethod]
        public void RemoveFirst()
        {
            list.AddFirst(10);
            list.AddFirst(20);
            list.RemoveFirst();
            Assert.AreEqual(10, list.First.Data);
            list.RemoveFirst();
            Assert.AreEqual(true, list.Empty);
        }

        [TestMethod]
        public void RemoveLast()
        {
            list.AddFirst(10);
            list.AddFirst(20);
            list.AddFirst(30);
            list.RemoveLast();
            Assert.AreEqual(20, list.Last.Data);
            list.RemoveLast();
            list.RemoveLast();
            Assert.AreEqual(true, list.Empty);
        }

        [TestMethod]
        public void ForEach()
        {
            list.AddLast(10);
            list.AddLast(20);
            list.AddLast(30);
            int n = 0;
            foreach (Node<int> i in list)
            {
                n += 10;
                Assert.AreEqual(n, i.Data);                
            }
        }
    }
}
